import { request } from '@/utils/request'
// get 请求应 json post 请求用 FromData 格式

//  request('/api/buyer/v1/menu/num')
export class Common {
    /**
     * @description 获取菜单接口数据
     * @return {HttpResponse} result
     */
    static async getMenuNum() {
        return request('/api/buyer/v1/menu/num')
    }

    static async getBasicData(data) {
        return request('/api/buyer/v1/get/basic/data', data)
    }

    static async getCurrencyData() {
        return request('/api/buyer/v1/currency/select')
    }

    static async getDeliveryData(delivery_type: any) {
        return request(`/api/buyer/v1/delivery?delivery_type=${delivery_type}`);
    }

    static async saveAddress(data: any) {
        return request('/api/buyer/v1/address/save', data, 'POST')
    }

    static async uploadFile(data: any) {
		try{
			return request('/api/buyer/v1/upload/files', data, 'POST')
		}catch(e){
			return null;
		}
    }	
	
	static async deleteFile(data: any) {
		try{
			return request('/api/buyer/v1/upload/files/delete', data, 'POST')
		}catch(e){
			return null;
		}
	}	
	

    static async getMyInfo() {
        return request('/api/buyer/v1/my/info')
    }

    static async editMyInfo(data: any) {
        return request('/api/buyer/v1/my/info/edit', data, 'POST')
    }

    static async getMessageMenuNum(data:any){
        return request('/api/buyer/v1/message/menu/num', data)
    }

    static async getMessageList(data: any) {
        return request('/api/buyer/v1/message/menu', data)
    }

    static async getMessageDetail(data: any) {
        return request('/api/buyer/v1/message/detail', data)
    }

    static async getMessageLine(data: any) {
        return request('/api/buyer/v1/message', data)
    }

    static async sendMessageLine(data: any) {
        
        return request('/api/buyer/v1/message/send', data, 'POST')
    }
	
	static async readAllMessages(data:any){		
		return request('/api/buyer/v1/message/read/all', data, 'GET')
	}

    static async getRecommandProduct(data: any) {
        return request('/api/buyer/v1/product/recommend', data)
    }

    static async getUserInfo() {
        return request('/api/user/info')
    }

    static async getCategory() {
        return request('/api/buyer/v1/category/get')
    }
    static async getEmailCode(data: any) {
        return request('/api/buyer/v1/email/verify', data, 'POST')
    }

    static async getMemberShip() {
        return request('/api/buyer/v1/membership/get')
    }

    static async toBuyMembership(data: any) {
        return request('/api/buyer/v1/membership/buy', data, 'POST')
    }

    static async getCartNum(data: any) {
        return request('/api/shop/cart/num', data, 'GET')
    }
	
	static async getUnits(data: any) {
	    return request('/api/get/unit', data, 'GET')
	}
	
	static async getBarcode(data: any) {
	    return request('/api/buyer/v1/showqrcode/get', data, 'GET')
	}
	
	static async unbind(data: any) {
	    return request('/api/buyer/v1/wx/unfollow', data, 'POST')
	}
	
	
	static async isLogin(){
		let userInfo=sessionStorage.getItem("userInfo");
		let flag=false;
		if (userInfo && userInfo!='undefined'){
			let info = eval('(' + userInfo + ')');
			if (info.login!=undefined && info.login==1){
				return "1";
			} 
		}
		
		let res=await this.getUserInfo();
		if (res.status==200 && res.data){
			let user=res.data.data;
			if (!user || user=="undefined" ){
				return "0";
			}else if (user.login==undefined || user.login==0){
				return "0";
			}else{
				user.login=1;
				sessionStorage.setItem("userInfo", JSON.stringify(user));
				return "1";
			}
		}else{
			return "0";
		}
	}
	
	static getCurrency(){
		/* let currencyId=localStorage.getItem("currencyId");
		if (currencyId==undefined  || currencyId==''){
			currencyId="3";
			localStorage.setItem("currencyId", "3");
		} */
		return 0;		
	}
	
	static setCurrency(currencyId){
		localStorage.setItem("currencyId", currencyId);
	}
}
